public class LinkedList <E> {
    private Node head;

    public LinkedList() {
      head = null;
    }

    public void addToFront(E item) {
        Node node = new Node(item);

        if (this.head == null) {
            this.head = node;
        } else{
            Node temp = head;
            this.head = node;
            this.head.next = temp;
        }
    }


    public void addToRear(E item) {
        Node newNode = new Node(item);
        if (this.head == null) {
            this.head = newNode;
        } else {
            
            Node temp = this.head;
            while(temp.next != null){
              temp = temp.next;
            }
            temp.next = newNode;
        }
    }

    public void print() {
        Node temp = this.head;
        while(temp.next != null){
            System.out.print(temp.item + " -> ");
            temp = temp.next;
        }
        System.out.println(temp.item);
    }
}

